<template>
  <div>
    <div class="top box box-pc box-ac">
      <div @click="Scan()" class="item box box-ver box-ac">
        <div class="icon icon-scan"></div>
        <div class="text">扫码</div>
      </div>
      <router-link to="/addManual" class="item box box-ver box-ac">
        <div class="icon icon-manual"></div>
        <div class="text">手工录入</div>
      </router-link>
    </div>
    <div @click="openBillList()" class="line box box-ac">
      <div class="icon icon-to-wx left"></div>
      <div class="box-f1 box right">
        <div class="box-f1">微信卡包导入发票</div>
        <div class="icon icon-arrow-right"></div>
      </div>
    </div>
    <div class="mybill box box-ver">
      <div class="tips">我的发票夹</div>
      <div class="list box box-ver">
        <router-link to="/myInvoice?type=2" class="item box">
          <div class="left box box-ac box-pc">
            <div class="icon box box-ver box-ac">
              <div class="num tx-c">&nbsp;{{dateObj.year}}&nbsp;</div>
              <div class="text tx-c">year</div>
            </div>
          </div>
          <div class="center-line"></div>
          <div class="right box box-f1 box-ac">本年发票</div>
        </router-link>
        <router-link to="/myInvoice?type=1" class="item box">
          <div class="left box box-ac box-pc">
            <div class="icon box box-ver box-ac">
              <div class="num tx-c">&nbsp;{{dateObj.month}}&nbsp;</div>
              <div class="text tx-c">month</div>
            </div>
          </div>
          <div class="center-line"></div>
          <div class="right box box-f1 box-ac">本月发票</div>
        </router-link>
        <router-link to="/myInvoice?type=0" class="item box">
          <div class="left box box-ac box-pc">
            <div class="icon box box-ver box-ac">
              <div class="num tx-c">&nbsp;{{dateObj.week}}&nbsp;</div>
              <div class="text tx-c">week</div>
            </div>
          </div>
          <div class="center-line"></div>
          <div class="right box box-f1 box-ac">本周发票</div>
        </router-link>
      </div>
    </div>
  </div>
</template>

<script>

import config from '@/js/config'
import { updateShare } from '../js/wxenv'
import { openToast } from '@/js/tools'
import { getWeek } from '@/js/common'
export default {
  name: 'app',
  data () {
    return {
      billConfig: {},
      invoiceDetailList: [],
      dateObj: {
        year: '',
        month: '',
        week: ''
      }
    }
  },
  mounted () {
    updateShare()
    this.getBillConfig()
    this.initDate()
  },
  methods: {
    initDate () {
      let weekStart = getWeek('s', 0)
      let weekEnd = getWeek('e', 0)
      this.dateObj.year = weekStart.split('-')[0]
      this.dateObj.month = weekStart.split('-')[1]
      this.dateObj.week = weekStart.split('-')[2] + '-' + weekEnd.split('-')[2]
    },
    Scan () {
      let _this = this
      // _this.$router.push('/addScanBill')
      wx.scanQRCode({
        needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
        scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码，默认二者都有
        success: function (res) {
          let result = res.resultStr // 当needResult 为 1 时，扫码返回的结果
          console.log(result, result.substring(0, 3), result.split(',').length)
          if (result.substring(0, 3) !== '01,' || result.split(',')[3].length !== 8) {
            openToast({
              msg: '请扫描发票二维码',
              duration: 2000
            })
          } else {
            // _this.$store.state.scanBillCode = result
            _this.$store.commit('scanBillCode', result)
            _this.$router.push('/addScanBill')
          }
        }
      })
    },
    openBillList () {
      let _this = this
      let billConfig = _this.billConfig
      wx.invoke('chooseInvoice', billConfig, function (res) {
        // console.log(JSON.stringify(res))
        let chooseInvoiceInfo = res.choose_invoice_info || '[]'
        chooseInvoiceInfo = JSON.parse(chooseInvoiceInfo)
        if (chooseInvoiceInfo.length > 0) {
          _this.$store.state.chooseInvoiceInfo = chooseInvoiceInfo
          _this.$router.push('/wxInvoiceList')
        }
      })
    },
    getBillConfig () {
      let url = config.baseUrl + `/vank/receipt/param_for_list1.do`
      // if (config.type === '1') {
      //   url = config.baseUrl + `/vank/receipt/param_for_list.do`
      // } else {
      //   url = config.baseUrl + `/vank/receipt/param_for_list2.do`
      // }
      this.$http({
        method: 'get',
        url: url,
        data: {}
      }).then(res => {
        this.billConfig = res.data
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../css/color';
@import '../css/mixins';
.top{
  background: linear-gradient(to top, #4daaed , #1595f0);
  height:3.13rem;
  .item{
    width:1.5rem;
    margin:0 .8rem;
    text-decoration: none;
    color:#FFF;
    .icon{
      width:1.18rem;
      height:1.18rem;
      &.icon-scan{
        @include bg-image('../img/icon-scan')
      }
      &.icon-manual{
        @include bg-image('../img/icon-manual');
      }
    }
    .text{
      margin-top:.4rem;
      font-size:.36rem;
    }
  }
}
.line{
  height: 1.14rem;
  font-size:.32rem;
  padding-left:.4rem;
  padding-right:.4rem;
  background-color: #FFF;
  text-decoration: none;
  color:#333;
  margin-top:.2rem;
  .left{
    &.icon{
      width:.54rem;
      height:.54rem;
      &.icon-to-wx{
        @include bg-image('../img/icon-to-wx')
      }
    }
  }
  .right{
    padding-left:.3rem;
  }
}
.mybill{
  padding:.3rem;
  padding-bottom:0;
  .tips{
    color:#666;
    font-size:.28rem;
  }
  .list{
    padding:.1rem;
    .item{
      margin-top:.1rem;
      margin-bottom:.1rem;
      height: 1.96rem;
      border-radius:.2rem;
      background: linear-gradient(to bottom left, #7fc9ff , #45acf7);
      color:#FFF;
      text-decoration: none;
      .left{
        width:1.8rem;
        .icon{
          width:1rem;
          height:.9rem;
          @include bg-image('../img/icon-bg-year');
          color:$themeColor;
          .num{
            margin-top:.3rem;
            font-size:.28rem
          }
          .text{
            font-size:.2rem
          }
        }
      }
      .right{
        font-size:.38rem;
        padding-left:.6rem;
      }
      .center-line{
        border-right:1px dashed $bgColor;
        height:1.96rem;
        position: absolute;
        left:1.8rem;
        &:before,&:after{
          content:'';
          position: absolute;
          left:-.07rem;
          display:block;
          width: 0;
          height: 0;
          border-left: .1rem solid transparent;
          border-right: .1rem solid transparent;
        }
        &:before{
          top:0;
          border-top: .12rem solid $bgColor;
        }
        &:after{
          bottom:0;
          border-bottom: .12rem solid $bgColor;
        }
      }
    }
  }
}
</style>
